package example.networkinstance.p03;

/**
 * @author 17976
 */
import java.net.InetAddress;
import java.net.UnknownHostException;

public class NetworkInfo {
    public static void main(String[] args) {
        try {
            InetAddress localHost = InetAddress.getLocalHost();
            String hostName = localHost.getHostName();
            System.out.println("主机名: " + hostName);
            String hostAddress = localHost.getHostAddress();
            System.out.println("IP地址: " + hostAddress);
        } catch (UnknownHostException e) {
            System.err.println("无法获取本机IP地址及主机名: " + e.getMessage());
            e.printStackTrace();
        }
    }
}
